home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / PacMan / FruitView.m < prev    next >
Encoding:
Text File  |  1992-06-27  |  1.6 KB  |  69 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "FruitView.h"
  5. #import <appkit/NXImage.h>
  6. #import <appkit/graphics.h>
  7. #import <dpsclient/psops.h>    // PSxxx functions
  8.  
  9. int fruits[FRUIT_LEVELS + 1] =
  10.     { 19, 5, 6, 8, 8, 9, 7, 7, 15, 15, 17, 17, 16, 16, 16, 16, 18 };
  11.  
  12.  
  13. @implementation FruitView
  14.  
  15. - initFrame:(const NXRect *)frm        // initialize instance
  16. {
  17.     [super initFrame:frm];
  18.     lastLevel = 0;
  19.     fruit = [NXImage findImageNamed:"Fruit.tiff"];
  20.     return self;
  21. }
  22.  
  23. - drawSelf:(NXRect *)rects :(int)rectCount  // standard rendering method
  24. {    // This is a hacked up mess.  Basically, it draw a horizontal line of
  25.     // fruits.  It starts at the left of the view and goes to the right.
  26.     // If you're level is higher than the width of the view would allow
  27.     // then we start on the left with a higher level of fruit so that the
  28.     // fruits will appear to scroll left as the level increases.
  29.     int j, jj, k, f;
  30.     NXRect from;
  31.     NXPoint pos;
  32.     
  33.     [self lockFocus];
  34.     PSsetgray(0.666);
  35.     NXRectFill(&bounds);
  36.     pos.y = 0; f = 0;
  37.     jj = bounds.size.width / FRUIT_SIZE - 1;
  38.     j = lastLevel - jj;
  39.     if (j<1) j = 1;
  40.     for (k=0; k<=jj; k++) {
  41.         f = k + j;
  42.         if (f > lastLevel) f = 0;
  43.         if (f > FRUIT_LEVELS) f = FRUIT_LEVELS;
  44.         f = fruits[f];
  45.         NXSetRect(&from,
  46.             (f % FRUIT_PER_ROW) * FRUIT_SIZE,
  47.             (f / FRUIT_PER_ROW) * FRUIT_SIZE,
  48.             FRUIT_SIZE, FRUIT_SIZE);
  49.         pos.x = k * FRUIT_SIZE;
  50.  
  51.         [fruit composite:NX_SOVER fromRect:&from toPoint:&pos];
  52.     }
  53.     
  54.     [self unlockFocus];
  55.     NXPing();
  56.     return self;
  57. }
  58.  
  59. - showLevel:(int)num                // draw all fruits up to level
  60. {
  61.     if (lastLevel == num) return self;
  62.     lastLevel = num;
  63.     [self update];
  64.     return self;
  65. }
  66.  
  67.  
  68. @end
  69.